﻿using System;

namespace ECommerce.Controls
{
	public partial class CheckoutPaymentMethod : BaseUserControl
	{
		private Service.IPaymentMethodService _PaymentMethodService;

		public int SelectedPaymentMethodID
		{
			get
			{
				if (RadioButtonListPaymentMethods.SelectedItem == null)
				{ 
				}
				return int.Parse(RadioButtonListPaymentMethods.SelectedValue);
			}
		}

		public bool CheckPaymentMethodHasSelected()
		{
			var result = RadioButtonListPaymentMethods.SelectedItem != null;

			if (!result)
			{
				RadioButtonListPaymentMethods.Focus();
			}

			return result;
		}

		protected void Page_Load(object sender, EventArgs e)
		{
		}

		protected void Page_PreRender(object sender, EventArgs e)
		{
			this.LSelectPaymentMethodTitle.Text = GetLocalResourceString("CheckoutPaymentMethod.SelectPaymentMethod.Title");

			BindPaymentMethod();
		}
 
		private void BindPaymentMethod()
		{
			if(_PaymentMethodService == null)
			{
				_PaymentMethodService = new Service.PaymentMethodService();
			}
			var paymentMethods = _PaymentMethodService.GetAllPaymentMethod();

			RadioButtonListPaymentMethods.DataSource = paymentMethods;
			RadioButtonListPaymentMethods.DataBind();
		}
	}
}